<?php

namespace app\admin\controller\test;

use app\admin\dao\MemberInfoDao;
use app\index\service\MemberService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use ShidianUtil\Utils\CheckUtil;
use think\exception\ValidateException;
use think\Request;

/**
 *
 * Class Test
 * @package app\admin\controller\test
 */
class Member
{
    public function save(Request $request, MemberService $memberService)
    {
        return;

        // 添加测试账号
        $phone = $request->param('phone');
        $type = $request->param('type', 0);
        $passwd = 111111;

        if (!CheckUtil::isPhoneNumber($phone)) {
            throw new ValidateException('请输入正确的手机号');
        }

        // 添加
        $repeat = \app\common\model\Member::where('phone', $phone)->find();
        if ($repeat) {
            throw new ValidateException('该手机号已存在');
        }

        $memberParams = [
            'phone' => $phone,
            'passwd' => $passwd,
            'channel' => 0,
        ];
        $member = $memberService->add($memberParams);

        $member->type = $type;
        if ($type == 1) {

            $member->type = 1;
            $member->save();

            // 添加律师信息
            $data = [
                'memberId' => $member->id,
                'realname' => $member->nickname,
                'provinceId' => 2570,
                'cityId' => 2571,
                'practiceNumber' => mt_rand(1000000, 9000000),
                'practicingLawFirm' => '时点律师事务所',
                'certificatePic' => '',
                'practiceTime' => 1451577600,
                'headImgUrl' => $member->headImgUrl,
                'type' => $type,
            ];

            $this->getMemberInfoDao()->insertActive($data, []);
        }

        return ApiResponse::success($member);
    }

    private function getMemberInfoDao(): MemberInfoDao
    {
        return app(MemberInfoDao::class);
    }
}
